package com.example.glide;

import android.util.Log;

import org.jetbrains.annotations.NotNull;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * author: liliang
 * date: 2020/8/24 6:27 PM
 */
public class RedirectInterceptor implements Interceptor {

    @NotNull
    @Override
    public Response intercept(Chain chain) throws IOException {
        okhttp3.Request request = chain.request();
        Response response = chain.proceed(request);
//        int code = response.code();
//        if (code == 200) {
//            //获取重定向的地址
//            String location = response.request().url().toString();
//            Log.e("TAG：", "location = " + location);
//            //重新构建请求
//            Request newRequest = request.newBuilder().url(location).build();
//            response = chain.proceed(newRequest);
//        }
        return response;
    }
}